

include "import32.inc"

format PE GUI at 0
entry start

section '.text' code readable executable

exit:
        or eax, -1
        int 0x40

align 4
start:
        xchg bx, bx
        push exit
        jmp   main

align 4
main:

        push    caption
        push    -1
        push    -1
        push    -1
        push    -1
        call    [con_init]
; C-equivalent of the following code:
; for (ebx=0;ebx<0x100;ebx++)
; {
;   con_printf(t1,ebx);
;   eax = con_set_flags(ebx);
;   con_write_asciiz(text);
;   con_set_flags(eax);
; }
; N.B. For efficiency result of first con_set_flags is not saved
;      in register, but is pushed beforehand to the stack
;      for second con_set_flags.
;      Note that such code cannot be generated by stdcall macros.
        xor	ebx, ebx
@@:
        push    ebx
        push    t1
        call    [con_printf]
        add     esp, 8
        push	ebx
        call	[con_set_flags]
        push	eax
        push    text
        call    [con_write_asciiz]
        call	[con_set_flags]
        inc	bl
        jnz	@b
        push    text2
        call    [con_write_asciiz]
        push    0
        call    [con_exit]
        ret

caption         db 'Console test - colors',0
t1              db 'Color 0x%02X: ',0
text            db 'This is sample text.',10,0
text2		db	27,'[7mAnd this is an example of '
		db	27,'[1;36;41mEsc'
		db	27,'[7m-sequences.',10,0


section '.idata' import data readable writeable

  library console,'CONSOLE.KDL'

  import console,\
        con_init,          'con_init',           \
        con_write_asciiz,  'con_write_asciiz',   \
        con_printf,        'con_printf',         \
        con_set_flags,     'con_set_flags',      \
        con_exit,          'con_exit'

